<?php

namespace DP\AbstractFactory;

use Exception;

class FactoryProducer
{
    public function getFactory($factory)
    {
        $factory = ucfirst(strtolower($factory));

        if (!$factory) {
            return null;
        }

        $factoryClass = '\DP\AbstractFactory\Factories\\' . $factory . 'Factory';

        try {
            return new $factoryClass;
        } catch (Exception $e) {
            echo '获取工厂失败，错误信息：' . $e->getMessage();
            return null;
        } catch (\Error $e) {
            echo $e->getMessage();
        }
    }
}
